package com.cheetah.start.module.system.domain;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.cheetah.start.common.base.BaseEntity;
import com.cheetah.start.common.util.PasswordUtil;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.noear.solon.validation.annotation.NotBlank;
import org.noear.solon.validation.annotation.NotNull;


/**
 * 系统管理员
 *
 * @author xjh
 * @date 2021/08/15
 */
@EqualsAndHashCode(callSuper = true)
@Data
@TableName(value = "sys_admin")
public class SysAdmin extends BaseEntity {

    /** 管理员 */
    @TableId(value = "admin_id")
    @NotNull(message = "ID不能为空")
    private Integer adminId;

    /** 账号 */
    @NotBlank(message = "账号不能为空")
    private String name;

    /** 密码 */
    @NotBlank(message = "密码不能为空")
    private String password;

    /** 真实姓名 */
    private String realName;

    /** 角色 id */
    @TableField(exist = false)
    private String roleIds;

    /** 性别 */
    private String sex;

    public void hashPwd(String newpwd) {
        this.password = PasswordUtil.hash(newpwd);
    }

    public void hashPwd() {
        this.password = PasswordUtil.hash(this.password);
    }
}
